/**
 * created by jsq on 2017/10/16
 */
//0416上线前重构

/**
 *Refactored by WangRuoNan on 2019/01/26
 * */
import React from 'react';
import {connect} from 'react-redux';
import {messages} from "share/common";
import {Button, Form, InputNumber, Checkbox, Radio, Row, Col, message, Icon, Popover, Modal} from 'antd';
import debounce from 'lodash.debounce';
import 'styles/setting/security-setting/security-setting.scss';
import SSService from 'containers/setting/security-setting/security-setting.service';
import BaseService from 'share/base.service';
import menuRoute from "routes/menuRoute";
const FormItem = Form.Item;
const CheckboxGroup = Checkbox.Group;
const RadioGroup = Radio.Group;


class SecuritySetting extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      loading: false,
      flag: true,
      enterpriseKey: false,
      selectedNoticeType: 0,
      createDataType: 1,
      securitySetting: {},
      ClientInfo: {
        clientId: "",
        clientSecret: ""
      },
      //passwordRule里面的元素顺序不能变
      passwordRule: [
        //小写字母
        {label: messages('setting.key979'/*小写字母*/), value: 'lowercase'},
        //大写字母
        {label: messages('setting.key980'/*大写字母*/), value: 'uppercase'},
        //数字
        {label: messages('setting.key981'/*数字*/), value: 'digital', disabled: true},
        //特殊字符
        {label: messages('setting.key982'/*特殊字符*/), value: 'specialCharacters'},
      ],
      noticeType: [
        //邮箱（邮箱将用于含附件消息如报销单电子件的推送）
        {
          label: messages('setting.key983'/*邮箱（邮箱将用于含附件消息如报销单电子件的推送）*/),
          value: '1001',
          disabled: true
        },
        //手机（海外手机不支持短消息推送）
        {
          label: <span> {messages('setting.key1020')/*手机*/}&nbsp;
            <span style={{ color: "rgba(0,0,0,0.4)"}}>{messages('setting.key1770')/*（海外手机不支持短消息推送）*/}</span>
                 </span>,
          value: '1002'
        },
      ],


      modifyPasswordByApi:[
        {
          label: <span>
                  {messages('setting.key985'/*允许员工通过接口修改密码*/)}&nbsp;
            <span style={{ color: "rgba(0,0,0,0.4)"}}>{messages('setting.key1771')/*（修改后员工用原密码将无法登录）*/}</span>
                 </span>,//"允许员工通过接口修改密码"
          value: true,
        },
      ],
      modifyMoblieEmail:[
        //勾选后员工可以在App上修改邮箱
        {
          label: messages('setting.key1021')/*邮箱*/,
          value: "email",
        },
        //勾选后员工可以在App上修改/删除手机号
        {
          label: messages('setting.key1020')/*手机*/,
          value: "mobile"
        },
        //勾选后员工可以在App上编辑银行卡
        {
          label: messages('setting.key1772')/*银行卡*/,
          value: "bank"
        },
        {
          label: messages('setting.key1773')/*证件信息*/,
          value: "card"
        },
      ]
    };
    this.handlePasswordRule = debounce(this.handlePasswordRule, 1000)
  }

  componentDidMount() {
    this.getCompanySecuritySetting();
    this.getClientInfo();
  }

  //获取安全设置数据
  getCompanySecuritySetting() {
    SSService.getCompanySecuritySetting(this.props.company.companyOID)
      .then((response) => {
        let selectedPasswordRule = [];
        let array = response.data.passwordRule.split("");
        for (let i = 0; i < array.length; i++) {
          if (array[i] === "1") {
            selectedPasswordRule.push(this.state.passwordRule[i].value)
          }
        }
        let noticeType = ["1001"];
        if (response.data.noticeType === 1003){
          noticeType.push("1002");
        }
        let modifyMoblieEmail = [];
        if(response.data.enableMobileModify){
          modifyMoblieEmail.push("mobile");
        }
        if(response.data.enableEmailModify){
          modifyMoblieEmail.push("email");
        }
        if(response.data.enableBankModify){
          modifyMoblieEmail.push("bank");
        }
        if(response.data.enableIdCardModify){
          modifyMoblieEmail.push("card");
        }
        let enablePasswordModify = [];
        enablePasswordModify.push(response.data.enablePasswordModify);

        let item = {
          noticeType: noticeType,
          modifyMoblieEmail: modifyMoblieEmail,
          selectedPasswordRule: selectedPasswordRule,
          enablePasswordModify: enablePasswordModify,//是否允许接口修改密码

          /*前后字段不一样，请注意*/
          defaultNoticeType: response.data.noticeType,
          defaultEnableMobileModify: response.data.enableMobileModify,
          defaultEnableEmailModify: response.data.enableEmailModify,
          defaultEnableBankModify: response.data.enableBankModify,
          defaultEnableIdCardModify: response.data.enableIdCardModify,
        };
        let securitySetting = Object.assign(response.data, item);
        this.setState({
          flag: false,
          securitySetting: securitySetting,
        })
      })
  }

  getClientInfo() {
    SSService.getClientInfo()
      .then((res) => {
        this.setState({
          ClientInfo: res.data
        })
      })
  }

  //处理选择密码规则
  handlePasswordRule = (checkedValue) => {
    let passwordRule = "";
    let securitySetting = this.state.securitySetting;
    this.state.passwordRule.map((item) => {
      if (this.isInArray(checkedValue, item.value) || item.value === 'digital') {
        passwordRule += "1"
      } else {
        passwordRule += "0"
      }
    });
    securitySetting.passwordRule = passwordRule;
    this.setState({
      securitySetting
    })
  };

  //处理选择通知类型
  handleNoticeType = (checkedValue) => {
    let flag = this.isInArray(checkedValue, 1002);
    let securitySetting = this.state.securitySetting;
    securitySetting.defaultNoticeType = flag ? 1003 : 1001;
    securitySetting.noticeType = checkedValue;
    this.setState({
      securitySetting
    })
  };
  //处理是否支持修改手机与邮箱
  handleModifyMoblieEmail = (checkedValue) => {
    let securitySetting = this.state.securitySetting;

    let mobile = this.isInArray(checkedValue, "mobile");
    let email = this.isInArray(checkedValue, "email");
    let bank = this.isInArray(checkedValue, "bank");
    let card = this.isInArray(checkedValue, "card");

    securitySetting.defaultEnableMobileModify = mobile;
    securitySetting.defaultEnableEmailModify = email;
    securitySetting.defaultEnableBankModify = bank;
    securitySetting.defaultEnableIdCardModify = card;

    this.setState({
      securitySetting
    })
  };

  //处理创建类型
  handleDataType = (e) => {
    let securitySetting = this.state.securitySetting;
    securitySetting.createDataType = e.target.value;
    this.setState({
      securitySetting
    })
  };

  //是否允许修改密码
  handleUpdatePassword = (value) => {
    let securitySetting = this.state.securitySetting;
    securitySetting.enablePasswordModify = value;
    this.setState({
      securitySetting
    })
  };

  //判断某个元素是否在数组中
  isInArray = (arr, val) => {
    let testStr = ',' + arr.join(",") + ",";
    return testStr.indexOf("," + val + ",") != -1;
  };

  handleEnterpriseKey = (flag) => {
    this.setState({
      enterpriseKey: flag,
    })
  };

  handleInteger = (e, key) => {
    let securitySetting = this.state.securitySetting;
    securitySetting[key] = e.target.value === '' ? this.state.securitySetting[key] : parseInt(e.target.value.toString().split(".")[0]);
  };

  renderEnterpriseKey() {
    return (
      this.state.enterpriseKey ?
        <span className="security-setting-display">
           {this.state.ClientInfo.clientSecret}
          <Button style={{marginLeft: 10}}
                  onClick={() => this.handleEnterpriseKey(false)}>
          {messages('setting.key988'/*点击隐藏*/)}
          </Button>
        </span>
        :
        <span className="security-setting-hide">
          <Button onClick={() => this.handleEnterpriseKey(true)}>
            {messages('setting.key989'/*查看*/)}
            </Button>
        </span>
    )
  }

  //有一个值为true，就保存true
  enablePasswordModifyIsTrue = (arr) => {
    for(let i = 0; i < arr.length; i++){
      if(arr[i]){
        return arr[i];
      }
    }
    return false;
  };


  beforeSummit = (e) => {
    const { securitySetting } = this.state;
    e.preventDefault();
    this.props.form.validateFieldsAndScroll((err, values) => {
      if(!err){
        if(values.enableLeavedEmployeesDelete){
          if(securitySetting.leavedEmployeesDeleteMonth){
            Modal.confirm({
              title: messages('setting.key1968',{arg1:securitySetting.leavedEmployeesDeleteMonth})/*{arg1}个月后将会对离职员工数据进行永久删除，会对业务数据造成查询及统计影响，是否继续？*/,
              content: '',
              okText: messages('setting.key1484')/*确认*/,
              cancelText: messages('setting.key1080')/*取消*/,
              onOk: this.handleSubmit,
            });
          }else{
            message.error(messages('setting.key1952')/*请输入离职员工处理的时长期限！*/);
          }
        }else{
          this.handleSubmit();
        }
      }
    })

  };

  handleSubmit = () => {
    const { securitySetting } = this.state;
    this.props.form.validateFieldsAndScroll((err, values) => {
        let enablePasswordModify = false;
        if(securitySetting.createDataType === 1002 && securitySetting.enablePasswordModify.length > 0){
          //如果不是接口创建方式，就不能通过接口修改密码
          enablePasswordModify = this.enablePasswordModifyIsTrue(securitySetting.enablePasswordModify);
        }
        this.setState({
          loading: true
        });
        let item = {
          enablePasswordModify: enablePasswordModify,

          backgroundAliveTime: securitySetting.backgroundAliveTime || 10 ,//登录安全验证
          /*
          * 此表单存在大量非双向数据绑定的字段，
          * 因为样式问题，很多组件最外层需要被html标签包裹，
          * 包裹后会出现initialValue值失效或同类型组件值联动等错误
          * 故很多组件都是onChange函数直接修改了securitySetting
          * */
          /*前后字段不一样，请注意*/
          noticeType: securitySetting.defaultNoticeType,
          enableMobileModify: securitySetting.defaultEnableMobileModify,
          enableEmailModify: securitySetting.defaultEnableEmailModify,
          enableBankModify: securitySetting.defaultEnableBankModify,
          enableIdCardModify: securitySetting.defaultEnableIdCardModify,

          /*表单中少量的双向数据绑定的字段*/
          tokenStorage: values.tokenStorage,//是否每次都重新登录
          exportSecurity: values.exportSecurity,//是否需要安全验证
          enableLeavedEmployeesDelete: values.enableLeavedEmployeesDelete,//离职员工处理，是否永久删除
          synOnActive: values.synOnActive,//人员同步到消费商
        };
        let params = Object.assign(securitySetting, item);
        SSService.updateCompanySecuritySetting(params)
          .then((response) => {
            message.success(messages("common.operate.success"));
            //重置redux
            BaseService.getCompany();
            this.getCompanySecuritySetting();
            this.setState({
              loading: false
            })
          }).catch(err => {
          this.setState({
            loading: false
          })
        })
    });
  };

  //处理创建类型
  handleSecurityLock = (e) => {
    let securitySetting = this.state.securitySetting;
    securitySetting.enableSecurityLock = e.target.value;
    this.setState({
      securitySetting
    })
  };

  passwordFromChange = (value)=>{
    const { securitySetting } = this.state;
    if((value &&  value > 0) && value >= 6){
      securitySetting.passwordLengthMin = parseInt(value);
    }else {
      securitySetting.passwordLengthMin = 6;
    }
    this.setState({
      securitySetting,
    })
  };

  passwordToChange = (value)=>{
    const { securitySetting } = this.state;
    if((value &&  value > 0) && value <= 32){
      securitySetting.passwordLengthMax = parseInt(value);
    }else {
      securitySetting.passwordLengthMax = 32;
    }
    this.setState({
      securitySetting,
    })
  };

  onValueChange = (value, attribute) => {
    const { securitySetting } = this.state;
    if(value &&  value > 0){
      securitySetting[attribute] = parseInt(value);
    }else {
      securitySetting[attribute] = 0;
    }
    this.setState({
      securitySetting,
    })
  };

  render() {
    const {getFieldDecorator} = this.props.form;
    const {tenantMode} = this.props;
    const {loading, flag, passwordRule, noticeType, securitySetting, modifyMoblieEmail, ClientInfo, modifyPasswordByApi} = this.state;
    const formItemLayout = {
      labelCol: {span: 7},
      wrapperCol: {span: 16, offset: 1},
    };
    const verticalRadio = {
      display: "block",
      marginBottom: 5
    };
    return (
      <div>
        {flag ? null :
          <div className="security-setting">
            <div id="3" className="security-setting-company">
              {/*企业id*/}
              {messages('setting.key990'/*企业ID*/)}： {ClientInfo.clientId}
            </div>
            <div className="security-setting-company">
              {/*企业密钥*/}
              {messages('setting.key991'/*企业密钥*/)}：{this.renderEnterpriseKey()}
            </div>
            <hr className="security-setting-slid"/>
            <Form onSubmit={this.beforeSummit}>
              {/*基础规则*/}
              <div className="security-setting-Rule">{messages('setting.key992'/*基础规则*/)}</div>
              {/*密码长度*/}
              <FormItem  {...formItemLayout} label={messages('setting.key993'/*密码长度：*/)}>
                    <InputNumber onBlur={(value) => this.handleInteger(value, 'passwordLengthMin')}
                                 min={6}
                                 step={1}
                                 onChange={this.passwordFromChange}
                                 value={securitySetting.passwordLengthMin}
                                 max={securitySetting.passwordLengthMax}
                                 disabled={!tenantMode}
                                 placeholder={messages("common.please.enter")}/>
                  {messages('setting.key994'/*到*/)}
                  <InputNumber onBlur={(value) => this.handleInteger(value, 'passwordLengthMax')}
                               style={{marginLeft: 5}}
                               disabled={!tenantMode}
                               onChange={this.passwordToChange}
                               value={securitySetting.passwordLengthMax}
                               min={securitySetting.passwordLengthMin}
                               max={32}
                               step={1}
                               placeholder={messages("common.please.enter")}/>
                  {messages('setting.key995'/*位*/)}
              </FormItem>

              <FormItem {...formItemLayout} label={messages('setting.key996'/*密码中必须包含：*/)}>
                <div className="horizon-checkbox">
                  <CheckboxGroup onChange={this.handlePasswordRule}
                                 disabled={!tenantMode}
                                 defaultValue={securitySetting.selectedPasswordRule}
                                 options={passwordRule}/>
                </div>
              </FormItem>

              {/*密码有效期*/}
              <FormItem {...formItemLayout} label={messages('setting.key997'/*密码有效期：*/)}>
                  <InputNumber onBlur={(value) => this.handleInteger(value, 'passwordExpireDays')}
                               min={0}
                               max={1095}
                               disabled={!tenantMode}
                               onChange={(value) => {this.onValueChange(value, "passwordExpireDays")}}
                               value={securitySetting.passwordExpireDays}
                               placeholder={messages("common.please.enter")}/>
                  {messages('setting.key692'/*天*/)}
                  <span className="gray-character">
                    （{messages('setting.key998'/*最多1095天，0表示永不过期，过期后不可以登录*/)}）
                    </span>
              </FormItem>

              {/*历史密码检查*/}
              <FormItem {...formItemLayout} label={messages('setting.key999'/*历史密码检查：*/)}>
                  {messages('setting.key1000'/*禁止当前使用*/)}&nbsp;
                  <InputNumber onBlur={(value) => this.handleInteger(value, 'passwordRepeatTimes')}
                               min={0}
                               max={24}
                               disabled={!tenantMode}
                               onChange={(value) => {this.onValueChange(value, "passwordRepeatTimes")}}
                               value={securitySetting.passwordRepeatTimes}
                               placeholder={messages("common.please.enter")}/>
                  {messages('setting.key1001'/*次密码*/)}
                  <span className="gray-character">（{messages('setting.key1002'/*最大24，0表示不启用历史密码检查策略*/)}）</span>
              </FormItem>

              {/*密码重试次数*/}
              <FormItem {...formItemLayout} label={messages('setting.key1003'/*密码重试次数*/)}>
                  <InputNumber onBlur={(value) => this.handleInteger(value, 'passwordAttemptTimes')}
                               min={0}
                               max={10}
                               disabled={!tenantMode}
                               onChange={(value) => {this.onValueChange(value, "passwordAttemptTimes")}}
                               value={securitySetting.passwordAttemptTimes}
                               placeholder={messages("common.please.enter")}/>
                  {messages('setting.key1004'/*次*/)}
              </FormItem>

              {/*自动解锁时间*/}
              <FormItem {...formItemLayout} label={messages('setting.key1005'/*自动解锁时间*/)}>
                  <InputNumber onBlur={(value) => this.handleInteger(value, 'autoUnlockDuration')}
                               min={0}
                               max={10080}
                               disabled={!tenantMode}
                               onChange={(value) => {this.onValueChange(value, "autoUnlockDuration")}}
                               value={securitySetting.autoUnlockDuration}
                               placeholder={messages("common.please.enter")}/>
                  {messages('setting.key1006'/*分钟*/)}
                <span className="gray-character"> {messages('setting.key1860')/*(如果设置为0，代表30分钟)*/}</span>

              </FormItem>

              <hr className="security-setting-slid"/>
              {/*其它规则*/}
              <div className="security-setting-Rule">
                {messages('setting.key1007'/*其它规则*/)}
              </div>
              <FormItem {...formItemLayout} label={messages('setting.key1008'/*账号失效时间：*/)}>
                <div> {messages('setting.key1953')/*员工离职*/}&nbsp;
                  <InputNumber onBlur={(value) => this.handleInteger(value, 'dimissionDelayDays')}
                               min={0}
                               max={180}
                               disabled={!tenantMode}
                               onChange={(value) => {this.onValueChange(value, "dimissionDelayDays")}}
                               value={securitySetting.dimissionDelayDays}
                               placeholder={messages("common.please.enter")}/>
                  {messages('setting.key1010'/*天后账号失效，将不能进行登录操作*/)}&nbsp;
                  （{messages('setting.key1011'/*最大180*/)}）
                </div>
              </FormItem>
              <FormItem {...formItemLayout} label={messages('setting.key1954')/*离职员工处理*/}>
                {getFieldDecorator('enableLeavedEmployeesDelete',{
                  valuePropName: 'checked',
                  initialValue: securitySetting.enableLeavedEmployeesDelete,
                })(
                  <Checkbox disabled={!tenantMode}>{messages('setting.key1955')/*永久删除*/}</Checkbox>
                )}
              </FormItem>
              {
                this.props.form.getFieldValue("enableLeavedEmployeesDelete") &&
                <Row style={{margin: "-27px 0 32px"}}>
                  <Col span={16} offset={8}>
                    <div> {messages('setting.key1956')/*勾选永久删除，员工离职日起*/}&nbsp;
                      <InputNumber onBlur={(value) => this.handleInteger(value, 'leavedEmployeesDeleteMonth')}
                                   min={6}
                                   disabled={!tenantMode}
                                   onChange={(value) => {this.onValueChange(value, "leavedEmployeesDeleteMonth")}}
                                   value={securitySetting.leavedEmployeesDeleteMonth}
                                   placeholder={messages("common.enter")}/>&nbsp;
                      {messages('setting.key1957')/*月后进行永久删除，且不可修复*/}，
                      <span style={{color: "red", fontSize: 16}}>{messages('setting.key1958')/*请谨慎使用*/}</span>
                    </div>
                  </Col>
                </Row>
              }
              {/*信息通知渠道*/}
              <FormItem {...formItemLayout} label={messages('setting.key1012'/*信息通知渠道：*/)}>
                <CheckboxGroup options={noticeType}
                               disabled={!tenantMode}
                               onChange={this.handleNoticeType}
                               defaultValue={securitySetting.noticeType}/>
              </FormItem>

              {/*员工是否可以修改*/}
              <FormItem {...formItemLayout} label={messages('setting.key1013'/*员工是否可以修改*/)}>
                <div className="horizon-checkbox">
                  <CheckboxGroup options={modifyMoblieEmail}
                                 disabled={!tenantMode}
                                 onChange={this.handleModifyMoblieEmail}
                                 defaultValue={securitySetting.modifyMoblieEmail ? securitySetting.modifyMoblieEmail : ["mobile"]}/>
                </div>
              </FormItem>

              <FormItem {...formItemLayout} label={messages('setting.key1014'/*员工和组织架构信息创建：*/)}>
                <div className="gray-character" style={{marginTop: 5}}>
                  {messages('setting.key1018'/*为确保信息的准确性，信息的同步方式只能选择一种，切换后会覆盖相同账号的信息*/)}
                </div>
                <RadioGroup onChange={this.handleDataType} value={securitySetting.createDataType}>
                  <Radio disabled={!tenantMode}
                         value={1001}
                         style={verticalRadio}>
                    <span>
                      {messages('setting.key1015'/*手动创建*/)}
                      <span className="gray-character">{messages('setting.key1016'/*（员工信息支持excel批量导入）*/)}</span>
                    </span>
                  </Radio>
                  <Radio disabled={!tenantMode}
                         value={1002}>
                    {messages('setting.key1017'/*接口同步*/)}
                  </Radio>
                </RadioGroup>
              </FormItem>

              {
                securitySetting.createDataType == 1002 &&
                <Row style={{margin: "-27px 0 32px"}}>
                  <Col span={16} offset={8}>
                    <CheckboxGroup options={modifyPasswordByApi}
                                   disabled={!tenantMode}
                                   onChange={this.handleUpdatePassword}
                                   defaultValue={securitySetting.enablePasswordModify}/>
                  </Col>
                </Row>
              }
              <FormItem {...formItemLayout} label={messages('setting.key2253')/*人员同步到消费商*/}>
                {getFieldDecorator('synOnActive',{
                  initialValue: securitySetting.synOnActive === undefined ? false : securitySetting.synOnActive
                })(
                  <RadioGroup>
                    <Radio value={false}
                           disabled={!tenantMode}>
                      {messages('setting.key2254')/*人员信息添加时*/}
                    </Radio>
                    <Radio value={true}
                           disabled={!tenantMode}>
                      {messages('setting.key2255')/*人员激活时*/}
                    </Radio>
                  </RadioGroup>
                )}
              </FormItem>
              <FormItem {...formItemLayout} label={messages('setting.key1022'/*web端每次都需要重新登录*/)}>
                {getFieldDecorator('tokenStorage',{
                  initialValue: securitySetting.tokenStorage
                })(
                  <RadioGroup>
                    <Radio value={'session'}
                           disabled={!tenantMode}>
                      {messages('setting.key1023'/*需要*/)}
                    </Radio>
                    <Radio value={'local'}
                           disabled={!tenantMode}>
                      {messages('setting.key1024'/*不需要*/)}
                    </Radio>
                  </RadioGroup>
                )}
              </FormItem>

              <FormItem {...formItemLayout} label={messages('setting.key1594')/*导出数据是否需要安全校验*/}>
                {getFieldDecorator('exportSecurity',{
                  initialValue: securitySetting.exportSecurity
                })(
                    <RadioGroup>
                      <Radio value={true}
                             style={verticalRadio}
                             disabled={!tenantMode}>
                        <span> {messages('setting.key1023')/*需要*/}
                          <span className="gray-character">{messages('setting.key1774')/*（推荐）*/}</span>
                        </span>
                      </Radio>
                      <Radio  value={false}
                              style={verticalRadio}
                              disabled={!tenantMode}>
                        <span> {messages('setting.key1024')/*不需要*/}
                          <span className="gray-character">{messages('setting.key1775')/*（不建议，如账号密码外泄可能有数据泄露的风险）*/}</span>
                        </span>
                    </Radio>
                  </RadioGroup>
                )}
              </FormItem>

              {/*登录安全验证*/}
              <FormItem {...formItemLayout}
                        label={
                          <span>{messages('setting.key1725')/*登录安全验证*/}
                            <Popover overlayStyle={{maxWidth: 350}}
                                     content={messages('setting.key1726')/*登录安全验证指通过指纹/人脸识别/安全密码再次验证用户身份，防止因手机丢失等造成的安全问题*/}>
                            &nbsp;<Icon type="question-circle-o" style={{cursor: "pointer", color: "rgba(0,0,0,0.5)"}}/>
                          </Popover>
                        </span>}>
                 <RadioGroup onChange={this.handleSecurityLock} value={securitySetting.enableSecurityLock} disabled={!tenantMode}>
                  <Radio value={true} style={verticalRadio}>
                    {messages('setting.key1086')/*启用*/}&nbsp;&nbsp;
                    {messages('setting.key1735')/*后台在线时间小于*/}&nbsp;
                    <InputNumber min={0}
                                 step={1}
                                 disabled={!tenantMode}
                                 value={securitySetting.backgroundAliveTime ? securitySetting.backgroundAliveTime : 10}
                                 onChange={(value) => {this.onValueChange(value, "backgroundAliveTime")}}/> {messages('setting.key1736')/*分钟，不需要身份验证*/}
                  </Radio>
                  <Radio value={false} style={verticalRadio}> {messages('setting.key1728')/*不启用*/}
                  </Radio>
                </RadioGroup>
              </FormItem>
              {this.props.profile["WEB.SetService.Display"] &&
              <FormItem>
                <Button type={"primary"}
                        onClick={()=>{this.context.router.push(menuRoute.getRouteItem('senior-service-open').url)}}> {messages('setting.key1738')/*开通服务*/}
                </Button>
              </FormItem>
              }

              <FormItem wrapperCol={{offset: 8}}>
                <Row style={{marginBottom: 50}}>
                  <Col span={3}>
                    <Button type="primary"
                            size='large'
                            htmlType="submit"
                            disabled={!tenantMode}
                            loading={loading}>
                      {/*保存*/}
                      {messages('common.save')}
                    </Button>
                  </Col>
                </Row>
              </FormItem>
            </Form>
          </div>
        }
      </div>
    )
  }
}

/*
 * noticeType：绑定类型:1001-邮箱,1002-手机,1003-手机+邮箱(目前暂时没有1002,因为邮箱是必选)
 dimissionDelayDays：延迟离职天数
 passwordExpireDays：密码有效期
 passwordRule：密码规则:小写字母，大写字母，数字，特殊字符，包含为1，不包含为0
 passwordLengthMin：密码最小长度
 passwordLengthMax：密码最大长度
 passwordRepeatTimes：禁止使用前几次密码
 createDataType：1001 手工创建和excle导入 1002 接口导入
 * */

SecuritySetting.contextTypes = {
  router: React.PropTypes.object
};

function mapStateToProps(state) {
  return {
    language: state.main.language,
    tenantMode: state.main.tenantMode,
    company: state.login.company,
    profile: state.login.profile,
  }
}

const WrappedSecuritySetting = Form.create()(SecuritySetting);
export default connect(mapStateToProps)(WrappedSecuritySetting);
